import numpy as np
def one_hot(data,windows = 15):
    data = data
    length = len(data)
    data_X = np.zeros((length,2*windows+1,21))
    data_Y = []
    for i in range(length):
        x=data[i].split(',')
        data_Y.append(int(x[4]))
        alphabet = 'ACDEFGHIKLMNPQRSTVWY-BJOUXZ'
        # define a mapping of chars to integers
        char_to_int = dict((c, i) for i, c in enumerate(alphabet))
        integer_encoded = [char_to_int[char] for char in x[5]]
        j = 0
        for value in integer_encoded:
            if value in [21, 22, 23, 24, 25, 26]:
                for k in range(21):
                    data_X[i][j][k] = 0.05
            else:
                data_X[i][j][value] = 1.0
            j = j + 1
    data_Y = np.array(data_Y)
    return data_X, data_Y

if __name__ == '__main__':
    f_r_train = open('hit-40/totalsum.csv')
    train_data = f_r_train.readlines()
    result = one_hot(train_data)
    # print(result)